package com.woniuxy.enjoylife.controller;

import com.woniuxy.enjoylife.entity.User_activity;
import com.woniuxy.enjoylife.service.UserAndActivityService;
import com.woniuxy.enjoylife.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("userAndActivity")
public class UserAndActivityController {
    @Autowired
    HttpServletRequest httpServletRequest;
    @Autowired
    UserAndActivityService userAndActivityService;
    /**
     * 参与活动
     */
    @GetMapping("participateActivities/{id}")
    public ResponseResult participateActivities(@PathVariable("id") Integer aid){

        ResponseResult responseResult = new ResponseResult();

        int uid = (int)httpServletRequest.getSession().getAttribute("id");

        User_activity user_activity = new User_activity().setAid(aid).setUid(uid);
        boolean result = userAndActivityService.saveOrUpdate(user_activity);
        if (result){
            responseResult.success();
        }else {
            responseResult.error();
        }
        return responseResult;
    }
}
